package jm.nj.demo22mian.apis;

import org.junit.Test;

import java.sql.*;


public class JdbcDemo_api3 {
    @Test
    public void demo() throws ClassNotFoundException, SQLException {
        //1.注册驱动

        Class.forName("com.mysql.jdbc.Driver");
        //java.sql.DriverManager.registerDriver(new com.mysql.jdbc.Driver());

        //2.连接数据库

        Connection conn = DriverManager.getConnection("jdbc:mysql:///day22","root","123456");

        //3.创建sql执行平台
        /*
        * java.sql.Statement: JDBC提供的执行平台接口类 statement
        * */
        Statement stmt = conn.createStatement();

        //4.执行sql
        ResultSet rs = stmt.executeQuery("select * from user");

        //5.处理执行结果
        while(rs.next()){
            Integer uid = rs.getInt("uid");
            String username = rs.getString("username");
            String password = rs.getString("password");
            Double salary = rs.getDouble("salary");
            Integer age = rs.getInt("age");
            Date registTime = rs.getDate("registTime");
            Timestamp lastupdate = rs.getTimestamp("lastupdate");
            System.out.println(uid+ "   "+username+ "     "+password+ "     "+salary+ "     "+age+ "        "+registTime+ "     "+lastupdate);
        }
        //释放资源
        rs.close();
        stmt.close();
        conn.close();
    }
}
